// 封装工具
//创建formidable实例并配置
const path = require("path")
const formidable = require("formidable");
// 3.实例化且配置  formidable 模块 
let form = new formidable.IncomingForm({
    uploadDir: path.resolve(process.cwd(), "./static"),  // 上传文件存储的路径
    keepExtensions: true   // 保持之前上传文件的后缀名称
});
module.exports = {
    returnData(req) {
        return new Promise((resolve, reject) => {
            form.parse(req, (err, fields, files) => {
                if (err) {
                    reject()
                    return console.log(err);
                }
                resolve({ ...fields, fileData: files.myimg.newFilename })
            })
        })
    }
}